package com.itany.shop.service.proxy;

import com.itany.shop.entity.User;
import com.itany.shop.exception.UserNotLoginException;
import com.itany.shop.factory.ObjectFactory;
import com.itany.shop.service.OrderService;
import com.itany.shop.service.ProductService;
import com.itany.shop.tran.TransactionManager;
import com.itany.shop.vo.Cart;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年12月22日 15:13
 */
public class OrderServiceProxy implements OrderService {
    private TransactionManager tran = (TransactionManager) ObjectFactory.getObject("tran");
    private OrderService orderService = (OrderService) ObjectFactory.getObject("orderServiceTarget");
    @Override
    public String createOrder(Cart cart, User user) throws UserNotLoginException {
        try {
            tran.begin();
            String no=orderService.createOrder(cart,user);
            tran.commit();
            return no;
        } catch (UserNotLoginException e) {
            tran.rollback();
            throw e;
        }
    }
}
